/**
 * @description Coze路由 API 接口
 */
const { CozeService } = require('@service/coze')
const Router = require('koa-router')
const { Resolve } = require('@lib/helper')
const { CozeValidator } = require('@validators/coze')

const router = new Router({
    prefix: '/coze'
})

const res = new Resolve()

/**
 * 登录
 */
router.post('/login', async ctx => {
    let err = null
    let data = null
    // 通过验证器校验参数是否通过
    const v = await new CozeValidator().validate(ctx)

    ;[err, data] = await CozeService.login({
        cozeUserName: v.get('body.cozeUserName'),
    });
    if (!err) {
        ctx.response.status = 200
        ctx.body = data
    } else {
        ctx.body = res.fail(err)
    }
})

module.exports = router